package com.sls.mall.product.web;

import com.sls.mall.product.entity.CategoryEntity;
import com.sls.mall.product.service.CategoryService;
import com.sls.mall.product.vo.Catelog2VO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @author lixue
 * @Title: IndexController
 * @ProjectName sls_mall2021
 * @Description: TODO
 * @date 2021/5/216:19
 */
@Controller
public class IndexController {

    @Autowired
    CategoryService categoryService;

    @GetMapping({"/","/index"})
    public String indexPage(Model model)
    {
        List<CategoryEntity> level1Categorys = categoryService.getLevel1Categorys();

        model.addAttribute("categorys",level1Categorys);

        return "index";
    }

    @ResponseBody
    @GetMapping("/index/catalog.json")
    public Map<Long, List<Catelog2VO>> getCatalogJson()
    {
        Map<Long, List<Catelog2VO>> map = categoryService.getCatalogJson();

        return map;
    }
}
